package com.example.friendmanager;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends AppCompatActivity {
    private EditText editname;
    private EditText editsex;
    private EditText editphone;
    private EditText editage;
    private Button btncommit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
      initview();
      btnclock();
    }
    private void initview(){
        editname=findViewById(R.id.edit_name);
        editsex=findViewById(R.id.edit_sex);
        editphone=findViewById(R.id.edit_phone);
        editage=findViewById(R.id.edit_age);
        btncommit=findViewById(R.id.btn_add);

    }
    private void btnclock(){
        Intent intent=new Intent(AddActivity.this,MainActivity.class);
        btncommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                crshi();
                startActivity(intent);
                finish();
            }
        });
    }
    private void crshi(){//数据库添加数据
        //添加
        myhelper mdbhelper=new myhelper(this,myhelper.FRIEND_INFO,null,1);
        ContentValues values=new ContentValues();
        values.put(myhelper.FRIEND_NAME,editname.getText().toString());
        values.put(mdbhelper.FRIEND_SEX,editsex.getText().toString());
        values.put(mdbhelper.FRIEND_PHONE,editphone.getText().toString());
        values.put(mdbhelper.FRIEND_AGE,editage.getText().toString());
        mdbhelper.insert(values);
    }
}